---
title: "NewsBordersAccPrompt_Oct2022"
output: html_document
date: "2022-10-30"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

Load data & libraries:
```{r, echo=FALSE}
#set working directory here:
setwd("~/Desktop/HCL_Active/NewsBorders/ACCPROMPT")
Sys.setlocale("LC_ALL", "C")
x <- read.csv("BorderProject_AccPr_Jul262022.csv", as.is = TRUE)

# load libraries
library(dplyr)
library(lubridate)
library(lme4)
library(MASS)
library(ggeffects)
library(lmerTest)
library(mediation)
library(readr)
library(tidyr)
library(corrr)
library(corrplot)
library(ggplot2)
library(nlme)
library(afex)
library(lmerTest)
library(MuMIn)
library(sjstats)
library(psych)
library(sandwich)
library(lmtest)
library(car)
library(fixest)
```

Omit previews.
```{r}
x <- x %>% filter(Status=="0")
```

Attention Trivial Filters.
```{r}
table(grepl("1", x$sm_filter) | grepl("2", x$sm_filter) | grepl("4", x$sm_filter))

table(x$captcha=="15")

x <- x %>% filter(captcha == "15")
x <- x %>% filter(Condition !="")
```


Differential Attrition Check.
```{r}
x$ClickCount <- pmax(x$timing_Click.Count, x$timing_Click.Count.1)

x$NoFeed <- NA
x$NoFeed[x$ClickCount==""] <- 1
x$NoFeed[x$ClickCount!=""] <- 0
table(x$NoFeed, x$Condition)

x %>% group_by(Condition) %>% summarise(mean(NoFeed))

x$Control <- ifelse(x$Condition=="Control",1,0)

chisq.test(x$Control, x$NoFeed)
table(x$Control, x$NoFeed)

x <- x %>% filter(NoFeed==0)
```

Practice Items.
```{r}
#first practice
table(x$practice1_1_1=="Off" & x$practice1_1_2=="On" & x$practice1_2_1 == "Off" & x$practice1_2_2 == "Off" & x$practice1_3_1 == "On" & x$practice1_3_2 == "Off")

#second practice
table(x$practice2_1_1=="Off" & x$practice2_1_2=="On" & x$practice2_2_1 == "Off" & x$practice2_2_2 == "Off" & x$practice2_3_1 == "On" & x$practice2_3_2 == "Off")

#either practice
table((x$practice1_1_1=="Off" & x$practice1_1_2=="On" & x$practice1_2_1 == "Off" & x$practice1_2_2 == "Off" & x$practice1_3_1 == "On" & x$practice1_3_2 == "Off")|(x$practice2_1_1=="Off" & x$practice2_1_2=="On" & x$practice2_2_1 == "Off" & x$practice2_2_2 == "Off" & x$practice2_3_1 == "On" & x$practice2_3_2 == "Off"))

x$PracticePass <- (x$practice1_1_1=="Off" & x$practice1_1_2=="On" & x$practice1_2_1 == "Off" & x$practice1_2_2 == "Off" & x$practice1_3_1 == "On" & x$practice1_3_2 == "Off")|(x$practice2_1_1=="Off" & x$practice2_1_2=="On" & x$practice2_2_1 == "Off" & x$practice2_2_2 == "Off" & x$practice2_3_1 == "On" & x$practice2_3_2 == "Off")

table(x$PracticePass)
```


Basic descriptives.

Duration.
```{r}
median(as.numeric(x$Duration..in.seconds.))/60
sd(as.numeric(x$Duration..in.seconds.))/60
```

Attention (pre-treat).
```{r}
x$Screen1 <- grepl("^4,7$",x$screen1)
x$Screen2 <- grepl("^3,5$",x$screen2)
x$Attn <- x$Screen1+x$Screen2
table(x$Attn)
```

Demos.
```{r}
mean(as.numeric(x$age), na.rm=T)
sd(as.numeric(x$age), na.rm=T)

table(x$gender)

table(x$race)
```

Politics
```{r}
table(x$politics)
mean(as.numeric(x$politics),na.rm=T)
sd(as.numeric(x$politics),na.rm=T)
```

Check Conditions.
```{r}
table(x$Condition)

table(x$Group)
```

DVs (cleaning).
```{r}
#share
x$cf1_share <- pmax(x$cf_overcount_1, x$cf_overcount_1.1)
x$cf2_share <- pmax(x$cf_hospitals_1, x$cf_hospitals_1.1)
x$cf3_share <- pmax(x$cf_gateswantscorona_1, x$cf_gateswantscorona_1.1)
x$vf1_share <- pmax(x$vf_abcnews_1, x$vf_abcnews_1.1)
x$vf2_share <- pmax(x$vf_military_1, x$vf_military_1.1)
x$vf3_share <- pmax(x$vf_watchbill_1, x$vf_watchbill_1.1)
x$fr1_share <- pmax(x$fr_unregisteredvotes_1, x$fr_unregisteredvotes_1.1)
x$fr2_share <- pmax(x$fr_ilhan_1, x$fr_ilhan_1.1)
x$fr3_share <- pmax(x$fr_mobboss_1, x$fr_mobboss_1.1)
x$fd1_share <- pmax(x$fd_fbi_1, x$fd_fbi_1.1)
x$fd2_share <- pmax(x$fd_tacobell_1, x$fd_tacobell_1.1)
x$fd3_share <- pmax(x$fd_white_1, x$fd_white_1.1)
x$cr1_share <- pmax(x$cr_inflammatory_1, x$cr_inflammatory_1.1)
x$cr2_share <- pmax(x$cr_maskmandate_1, x$cr_maskmandate_1.1)
x$cr3_share <- pmax(x$cr_covid_1, x$cr_covid_1.1)
x$vr1_share <- pmax(x$vr_bidenvac_1, x$vr_bidenvac_1.1)
x$vr2_share <- pmax(x$vr_canada_1, x$vr_canada_1.1)
x$vr3_share <- pmax(x$vr_cdc_1, x$vr_cdc_1.1)
x$rr1_share <- pmax(x$rr_hunter_1, x$rr_hunter_1.1)
x$rr2_share <- pmax(x$rr_newsmax_1, x$rr_newsmax_1.1)
x$rr3_share <- pmax(x$rr_consmemes_1, x$rr_consmemes_1.1)
x$rd1_share <- pmax(x$rd_bisexuality_1, x$rd_bisexuality_1.1)
x$rd2_share <- pmax(x$rd_mediapraise_1, x$rd_mediapraise_1.1)
x$rd3_share <- pmax(x$rd_soccer_1, x$rd_soccer_1.1)

x$s1_share <- pmax(x$s_hiking_1, x$s_hiking_1.1)
x$s2_share <- pmax(x$s_family_1, x$s_family_1.1)
x$s3_share <- pmax(x$s_city_1, x$s_city_1.1)
x$s4_share <- pmax(x$s_daddy_1, x$s_daddy_1.1)
x$s5_share <- pmax(x$s_band_1, x$s_band_1.1)
x$s6_share <- pmax(x$s_biking_1, x$s_biking_1.1)
x$s7_share <- pmax(x$s_skiing_1, x$s_skiing_1.1)
x$s8_share <- pmax(x$s_rides_1, x$s_rides_1.1)
x$s9_share <- pmax(x$s_pbj_1, x$s_pbj_1.1)
x$s10_share <- pmax(x$s_bestfriend_1, x$s_bestfriend_1.1)
x$s11_share <- pmax(x$s_anniversary_1, x$s_anniversary_1.1)
x$s12_share <- pmax(x$s_cafe_1, x$s_cafe_1.1)
x$s13_share <- pmax(x$s_dinnertable_1, x$s_dinnertable_1.1)
x$s14_share <- pmax(x$s_icecream_1, x$s_icecream_1.1)
x$s15_share <- pmax(x$s_happybirthday_1, x$s_happybirthday_1.1)
x$s16_share <- pmax(x$s_baking_1, x$s_baking_1.1)
x$s17_share <- pmax(x$s_dog_1, x$s_dog_1.1)
x$s18_share <- pmax(x$s_bestfri_1, x$s_bestfri_1.1)
x$s19_share <- pmax(x$s_look_1, x$s_look_1.1)
x$s20_share <- pmax(x$s_mans_1, x$s_mans_1.1)
x$s21_share <- pmax(x$s_loveshiking_1, x$s_loveshiking_1.1)
x$s22_share <- pmax(x$s_hanging_1, x$s_hanging_1.1)
x$s23_share <- pmax(x$s_superhero_1, x$s_superhero_1.1)
x$s24_share <- pmax(x$s_playdate_1, x$s_playdate_1.1)

x$ds1_share <- pmax(x$ds_covid_1, x$ds_covid_1.1)
x$ds2_share <- pmax(x$ds_strike_1, x$ds_strike_1.1)
x$ds3_share <- pmax(x$ds_vote_1, x$ds_vote_1.1)
x$ds4_share <- pmax(x$ds_asian_1, x$ds_asian_1.1)
x$ds5_share <- pmax(x$ds_vac_1, x$ds_vac_1.1)
x$ds6_share <- pmax(x$ds_deb_1, x$ds_deb_1.1)
x$ds7_share <- pmax(x$ds_forestfire_1, x$ds_forestfire_1.1)
x$ds8_share <- pmax(x$ds_pol_1, x$ds_pol_1.1)
x$ds9_share <- pmax(x$ds_healthcare_1, x$ds_healthcare_1.1)
x$ds10_share <- pmax(x$ds_diversity_1, x$ds_diversity_1.1)
x$ds11_share <- pmax(x$ds_trans_1, x$ds_trans_1.1)
x$ds12_share <- pmax(x$ds_phone_1, x$ds_phone_1.1)
x$rs1_share <- pmax(x$rs_school_1, x$rs_school_1.1)
x$rs2_share <- pmax(x$rs_trumpw_1, x$rs_trumpw_1.1)
x$rs3_share <- pmax(x$rs_repmom_1, x$rs_repmom_1.1)
x$rs4_share <- pmax(x$rs_mask_1, x$rs_mask_1.1)
x$rs5_share <- pmax(x$rs_prolife_1, x$rs_prolife_1.1)
x$rs6_share <- pmax(x$rs_bathing_1, x$rs_bathing_1.1)
x$rs7_share <- pmax(x$rs_taxes_1, x$rs_taxes_1.1)
x$rs8_share <- pmax(x$rs_booster_1, x$rs_booster_1.1)
x$rs9_share <- pmax(x$rs_mand_1, x$rs_mand_1.1)
x$rs10_share <- pmax(x$rs_cafe_1, x$rs_cafe_1.1)
x$rs11_share <- pmax(x$rs_higher_1, x$rs_higher_1.1)
x$rs12_share <- pmax(x$rs_july_1, x$rs_july_1.1)
```


```{r}
#like
x$cf1_like <- pmax(x$cf_overcount_2, x$cf_overcount_2.1)
x$cf2_like <- pmax(x$cf_hospitals_2, x$cf_hospitals_2.1)
x$cf3_like <- pmax(x$cf_gateswantscorona_2, x$cf_gateswantscorona_2.1)
x$vf1_like <- pmax(x$vf_abcnews_2, x$vf_abcnews_2.1)
x$vf2_like <- pmax(x$vf_military_2, x$vf_military_2.1)
x$vf3_like <- pmax(x$vf_watchbill_2, x$vf_watchbill_2.1)
x$fr1_like <- pmax(x$fr_unregisteredvotes_2, x$fr_unregisteredvotes_2.1)
x$fr2_like <- pmax(x$fr_ilhan_2, x$fr_ilhan_2.1)
x$fr3_like <- pmax(x$fr_mobboss_2, x$fr_mobboss_2.1)
x$fd1_like <- pmax(x$fd_fbi_2, x$fd_fbi_2.1)
x$fd2_like <- pmax(x$fd_tacobell_2, x$fd_tacobell_2.1)
x$fd3_like <- pmax(x$fd_white_2, x$fd_white_2.1)
x$cr1_like <- pmax(x$cr_inflammatory_2, x$cr_inflammatory_2.1)
x$cr2_like <- pmax(x$cr_maskmandate_2, x$cr_maskmandate_2.1)
x$cr3_like <- pmax(x$cr_covid_2, x$cr_covid_2.1)
x$vr1_like <- pmax(x$vr_bidenvac_2, x$vr_bidenvac_2.1)
x$vr2_like <- pmax(x$vr_canada_2, x$vr_canada_2.1)
x$vr3_like <- pmax(x$vr_cdc_2, x$vr_cdc_2.1)
x$rr1_like <- pmax(x$rr_hunter_2, x$rr_hunter_2.1)
x$rr2_like <- pmax(x$rr_newsmax_2, x$rr_newsmax_2.1)
x$rr3_like <- pmax(x$rr_consmemes_2, x$rr_consmemes_2.1)
x$rd1_like <- pmax(x$rd_bisexuality_2, x$rd_bisexuality_2.1)
x$rd2_like <- pmax(x$rd_mediapraise_2, x$rd_mediapraise_2.1)
x$rd3_like <- pmax(x$rd_soccer_2, x$rd_soccer_2.1)

x$s1_like <- pmax(x$s_hiking_2, x$s_hiking_2.1)
x$s2_like <- pmax(x$s_family_2, x$s_family_2.1)
x$s3_like <- pmax(x$s_city_2, x$s_city_2.1)
x$s4_like <- pmax(x$s_daddy_2, x$s_daddy_2.1)
x$s5_like <- pmax(x$s_band_2, x$s_band_2.1)
x$s6_like <- pmax(x$s_biking_2, x$s_biking_2.1)
x$s7_like <- pmax(x$s_skiing_2, x$s_skiing_2.1)
x$s8_like <- pmax(x$s_rides_2, x$s_rides_2.1)
x$s9_like <- pmax(x$s_pbj_2, x$s_pbj_2.1)
x$s10_like <- pmax(x$s_bestfriend_2, x$s_bestfriend_2.1)
x$s11_like <- pmax(x$s_anniversary_2, x$s_anniversary_2.1)
x$s12_like <- pmax(x$s_cafe_2, x$s_cafe_2.1)
x$s13_like <- pmax(x$s_dinnertable_2, x$s_dinnertable_2.1)
x$s14_like <- pmax(x$s_icecream_2, x$s_icecream_2.1)
x$s15_like <- pmax(x$s_happybirthday_2, x$s_happybirthday_2.1)
x$s16_like <- pmax(x$s_baking_2, x$s_baking_2.1)
x$s17_like <- pmax(x$s_dog_2, x$s_dog_2.1)
x$s18_like <- pmax(x$s_bestfri_2, x$s_bestfri_2.1)
x$s19_like <- pmax(x$s_look_2, x$s_look_2.1)
x$s20_like <- pmax(x$s_mans_2, x$s_mans_2.1)
x$s21_like <- pmax(x$s_loveshiking_2, x$s_loveshiking_2.1)
x$s22_like <- pmax(x$s_hanging_2, x$s_hanging_2.1)
x$s23_like <- pmax(x$s_superhero_2, x$s_superhero_2.1)
x$s24_like <- pmax(x$s_playdate_2, x$s_playdate_2.1)

x$ds1_like <- pmax(x$ds_covid_2, x$ds_covid_2.1)
x$ds2_like <- pmax(x$ds_strike_2, x$ds_strike_2.1)
x$ds3_like <- pmax(x$ds_vote_2, x$ds_vote_2.1)
x$ds4_like <- pmax(x$ds_asian_2, x$ds_asian_2.1)
x$ds5_like <- pmax(x$ds_vac_2, x$ds_vac_2.1)
x$ds6_like <- pmax(x$ds_deb_2, x$ds_deb_2.1)
x$ds7_like <- pmax(x$ds_forestfire_2, x$ds_forestfire_2.1)
x$ds8_like <- pmax(x$ds_pol_2, x$ds_pol_2.1)
x$ds9_like <- pmax(x$ds_healthcare_2, x$ds_healthcare_2.1)
x$ds10_like <- pmax(x$ds_diversity_2, x$ds_diversity_2.1)
x$ds11_like <- pmax(x$ds_trans_2, x$ds_trans_2.1)
x$ds12_like <- pmax(x$ds_phone_2, x$ds_phone_2.1)
x$rs1_like <- pmax(x$rs_school_2, x$rs_school_2.1)
x$rs2_like <- pmax(x$rs_trumpw_2, x$rs_trumpw_2.1)
x$rs3_like <- pmax(x$rs_repmom_2, x$rs_repmom_2.1)
x$rs4_like <- pmax(x$rs_mask_2, x$rs_mask_2.1)
x$rs5_like <- pmax(x$rs_prolife_2, x$rs_prolife_2.1)
x$rs6_like <- pmax(x$rs_bathing_2, x$rs_bathing_2.1)
x$rs7_like <- pmax(x$rs_taxes_2, x$rs_taxes_2.1)
x$rs8_like <- pmax(x$rs_booster_2, x$rs_booster_2.1)
x$rs9_like <- pmax(x$rs_mand_2, x$rs_mand_2.1)
x$rs10_like <- pmax(x$rs_cafe_2, x$rs_cafe_2.1)
x$rs11_like <- pmax(x$rs_higher_2, x$rs_higher_2.1)
x$rs12_like <- pmax(x$rs_july_2, x$rs_july_2.1)
```

Long Data.
```{r}
x_share <- x %>% dplyr::select(ResponseId, politics, Condition, Group, PracticePass, Attn, cf1_share:rs12_share)

x_longS <- gather(x_share, item, share, cf1_share:rs12_share)

length(unique(x_longS$item))
```

```{r}
x_like <- x %>% dplyr::select(ResponseId, politics, Condition, Group, PracticePass, Attn, cf1_like:rs12_like)

x_longL <- gather(x_like, item, like, cf1_like:rs12_like)

length(unique(x_longS$item))
```

```{r}
x_longS$itemU <- substr(x_longS$item,1,nchar(x_longS$item)-6)
x_longL$itemU <- substr(x_longL$item,1,nchar(x_longL$item)-5)

x_longL <- x_longL %>% dplyr::select(ResponseId, itemU, like)

x_long <- left_join(x_longS, x_longL, by=c("ResponseId", "itemU"))

head(x_long)
```

Additional variable creation.

Post type.
```{r}
x_long$item_type <- NA

x_long$item_type[grepl("^cf", x_long$itemU)|grepl("^vf", x_long$itemU)|grepl("^fr", x_long$itemU)|grepl("^fd", x_long$itemU)] <- 0

x_long$item_type[grepl("^cr", x_long$itemU)|grepl("^vr", x_long$itemU)|grepl("^rr", x_long$itemU)|grepl("^rd", x_long$itemU)] <- 1

x_long$item_type[grepl("^s", x_long$itemU)] <- 2

x_long$item_type[grepl("^ds", x_long$itemU)|grepl("^rs", x_long$itemU) ] <- 3

x_long$item_type <- as.factor(x_long$item_type)
table(x_long$item_type)
```

Social dummy.
```{r}
x_long$social <- NA

x_long$social[grepl("^cf", x_long$itemU)|grepl("^vf", x_long$itemU)|grepl("^fr", x_long$itemU)|grepl("^fd", x_long$itemU)|grepl("^cr", x_long$itemU)|grepl("^vr", x_long$itemU)|grepl("^rr", x_long$itemU)|grepl("^rd", x_long$itemU)] <- 0

x_long$social[grepl("^s", x_long$itemU)|grepl("^ds", x_long$itemU)|grepl("^rs", x_long$itemU)] <- 1

x_long$social <- as.factor(x_long$social)
```

Political social dummy.
```{r}
x_long$socpol <- 0

x_long$socpol[grepl("^ds", x_long$itemU)|grepl("^rs", x_long$itemU) ] <- 1

x_long$socpol <- as.factor(x_long$socpol)
```

True dummy.
```{r}
x_long$true <- 0

x_long$true[grepl("^cr", x_long$itemU)|grepl("^vr", x_long$itemU)|grepl("^rr", x_long$itemU)|grepl("^rd", x_long$itemU)] <- 1

x_long$true <- as.factor(x_long$true)
```

Share, Like DVs.
```{r}
x_long$ShareDV <- NA
x_long$ShareDV[x_long$share=="On"] <- 1
x_long$ShareDV[x_long$share=="Off"] <- 0

x_long$LikeDV <- NA
x_long$LikeDV[x_long$like=="On"] <- 1
x_long$LikeDV[x_long$like=="Off"] <- 0
```

Condition IV.
```{r}
x_long$ConditionIV <- NA
x_long$ConditionIV[x_long$Condition=="Control"] <- 0
x_long$ConditionIV[x_long$Condition=="Acc"] <- 1
x_long$ConditionIV[x_long$Condition=="1B"] <- 2

x_long$ConditionIV <- as.factor(x_long$ConditionIV)
```

Engagement DV.
```{r}
x_long$Engage <- NA
x_long$Engage[x_long$ShareDV==1 | x_long$LikeDV==1] <- 1
x_long$Engage[x_long$ShareDV==0 & x_long$LikeDV==0] <- 0
```


PRACTICE & ATTENTION FILTERS (un-comment to apply filters here).
```{r}
#x_long <- x_long %>% filter(PracticePass==T)

#x_long <- x_long %>% filter(Attn>0)
```

Main Analyses.
```{r}
length(unique(x_long$ResponseId))
```

Pre-registered Main Analyses.

Sharing.
```{r}
fit <- glm(ShareDV ~ item_type*ConditionIV, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_share, file = "m1.csv", quote = FALSE, row.names = F)
```

Compare Treatments on Discernment
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type1:ConditionIV1 = item_type1:ConditionIV2", test="F")
```

Border on News
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("ConditionIV2 = 0", "item_type1:ConditionIV2=0"), test="F")
```

Border on Social
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("item_type2:ConditionIV2 = 0", "item_type3:ConditionIV2=0"), test="F")
```

Liking.
```{r}
fit <- glm(LikeDV ~ item_type*ConditionIV, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_like, file = "m2.csv", quote = FALSE, row.names = F)
```

Compare Treatments on Discernment
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type1:ConditionIV1 = item_type1:ConditionIV2", test="F")
```

Border on News
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("ConditionIV2 = 0", "item_type1:ConditionIV2=0"), test="F")
```

Border on Social
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("item_type2:ConditionIV2 = 0", "item_type3:ConditionIV2=0"), test="F")
```

Engaging.
```{r}
fit <- glm(Engage ~ item_type*ConditionIV, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_engage <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_engage, file = "m3.csv", quote = FALSE, row.names = F)
```

Compare Treatments on Discernment
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type1:ConditionIV1 = item_type1:ConditionIV2", test="F")
```

Border on News
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("ConditionIV2 = 0", "item_type1:ConditionIV2=0"), test="F")
```

Border on Social
```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), c("item_type2:ConditionIV2 = 0", "item_type3:ConditionIV2=0"), test="F")
```

Control-only
```{r}
x_longC <- x_long %>% filter(ConditionIV==0)
```

Sharing.
```{r}
fit <- glm(ShareDV ~ item_type, data=x_longC)

clusters <- cbind(x_longC$ResponseId, x_longC$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_share, file = "m4.csv", quote = FALSE, row.names = F)
```

```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type1 = item_type3", test="F")
```

```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type3 = item_type2", test="F")
```

Liking.
```{r}
fit <- glm(LikeDV ~ item_type, data=x_longC)

clusters <- cbind(x_longC$ResponseId, x_longC$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_like, file = "m5.csv", quote = FALSE, row.names = F)
```

```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type1 = item_type3", test="F")
```

```{r}
linearHypothesis(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0"), "item_type3 = item_type2", test="F")
```

Collapse Treatment Conditions
```{r}
x_long$Treat <- NA
x_long$Treat[x_long$ConditionIV==0] <- 0
x_long$Treat[x_long$ConditionIV==1|x_long$ConditionIV==2] <- 1
x_long$Treat <- as.factor(x_long$Treat)
```

Sharing.
```{r}
fit <- glm(ShareDV ~ item_type*Treat, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_share, file = "m6.csv", quote = FALSE, row.names = F)
```

Liking.
```{r}
fit <- glm(LikeDV ~ item_type*Treat, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_like, file = "m7.csv", quote = FALSE, row.names = F)
```

Engaging.
```{r}
fit <- glm(Engage ~ item_type*Treat, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_engage <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

#write.csv(model_engage, file = "m8.csv", quote = FALSE, row.names = F)
```

Secondary Analyses.

z-score Parisanship
```{r}
x_long$zpartisan <- scale(as.numeric(x_long$politics))
hist(x_long$zpartisan)
```

Dem/Rep posts
```{r}
x_long$item_pol <- NA

x_long$item_pol[grepl("^s", x_long$itemU)] <- "N"

x_long$item_pol[grepl("^fr", x_long$itemU)|grepl("^rr", x_long$itemU)|grepl("^rs", x_long$itemU)] <- "R"

x_long$item_pol[grepl("^fd", x_long$itemU)|grepl("^rd", x_long$itemU)|grepl("^ds", x_long$itemU)] <- "D"

x_long$item_pol[grepl("^cf", x_long$itemU)|grepl("^vf", x_long$itemU)|grepl("^cr", x_long$itemU)|grepl("^vr", x_long$itemU)] <- "COVID"
```

Concordance variable
```{r}
x_long$Concord <- NA
x_long$Concord[x_long$item_pol=="N"] <- 0
x_long$Concord[x_long$item_pol=="COVID"] <- 0

x_long$Concord[x_long$item_pol=="D" & x_long$zpartisan<0] <- 0.5
x_long$Concord[x_long$item_pol=="D" & x_long$zpartisan>0] <- -0.5

x_long$Concord[x_long$item_pol=="R" & x_long$zpartisan<0] <- -0.5
x_long$Concord[x_long$item_pol=="R" & x_long$zpartisan>0] <- 0.5

table(x_long$Concord)
```

Note pre-reg deviation: apolitical social & COVID items are omitted from analyses (rather than coded as 0 and classified via pretest, respectively).

Note: package 'fixest' used in place of 'sandiwch' & 'lmtest' packages for these cluster robust standard error analyses for model performance.

Sharing.

Omit apolitical social & COVID items.
```{r}
x_long2 <- x_long %>% filter(Concord != 0 | is.na(Concord))
```

```{r}
fit <- feols(ShareDV ~ item_type*ConditionIV*Concord*zpartisan, data=x_long2)
(model_share <- summary(fit, cluster=c("ResponseId", "itemU")))
```

Liking.
```{r}
fit <- feols(LikeDV ~ item_type*ConditionIV*Concord*zpartisan, data=x_long2)
(model_like <- summary(fit, cluster=c("ResponseId", "itemU")))
```

Engaging.
```{r}
fit <- feols(Engage ~ item_type*ConditionIV*Concord*zpartisan, data=x_long2)
(model_engage <- summary(fit, cluster=c("ResponseId", "itemU")))
```

Just zpartisan moderation (all headlines)
```{r}
fit <- glm(ShareDV ~ item_type*ConditionIV*zpartisan, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
```

```{r}
fit <- glm(LikeDV ~ item_type*ConditionIV*zpartisan, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
```

```{r}
fit <- glm(Engage ~ item_type*ConditionIV*zpartisan, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_engage <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
```

Simple check that concordant political social posts were engaged with more.
```{r}
z <- x_long %>% filter(item_type==3)

fit <- feols(ShareDV ~ Concord, data=z)
(model_share <- summary(fit, cluster=c("ResponseId", "itemU")))

fit <- feols(LikeDV ~ Concord, data=z)
(model_like <- summary(fit, cluster=c("ResponseId", "itemU")))

fit <- feols(Engage ~ Concord, data=z)
(model_engage <- summary(fit, cluster=c("ResponseId", "itemU")))
```


PLOTS.

Investigate High False Share Rates
```{r}
itemshares <- x_long %>% filter(x_long$ConditionIV==0 & (item_type==0 | item_type==1)) %>% group_by(itemU) %>% summarise(mshare=mean(ShareDV, na.rm=T))

arrange(itemshares, desc(mshare))
```

```{r}
x_long <- left_join(x_long, itemshares, by="itemU")

x_long %>% filter(x_long$ConditionIV==0 & (item_type==0 | item_type==1)) %>% ggplot(aes(x=reorder(itemU, mshare), y=ShareDV, fill=true))+stat_summary(fun=mean, geom="bar")+stat_summary(fun.data = mean_cl_normal, geom="errorbar", width=0.2)+theme_classic()+ylab("Sharing Probability")+xlab("News Post Code")+scale_fill_manual(values=c("#FFCB32", "#2F7604"))+ guides(fill=guide_legend(title="Post Veracity \n(0=False, 1=True)"))
```

```{r}
x_longCN <- x_long %>% filter(ConditionIV==0 & (item_type==0 | item_type==1))
fit <- glm(ShareDV ~ item_type, data=x_longCN)

clusters <- cbind(x_longCN$ResponseId, x_longCN$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

x_longCN2 <- x_longCN %>% filter(itemU!="fr1" & itemU!="cf2")
fit <- glm(ShareDV ~ item_type, data=x_longCN2)

clusters <- cbind(x_longCN2$ResponseId, x_longCN2$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
```

Coefficient Plots.

SHARING
```{r}
AccOnlyb <- c()
AccOnlySE <- c()

AccBorderb <- c()
AccBorderSE <- c()
```

```{r}
fit <- glm(ShareDV ~ ConditionIV, data=x_long[x_long$item_type==0,])

clusters <- cbind(x_long[x_long$item_type==0,]$ResponseId, x_long[x_long$item_type==0,]$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlyb <- append(AccOnlyb, model_share[2])
AccOnlySE <- append(AccOnlySE, model_share[2,2])

AccBorderb <- append(AccBorderb, model_share[3])
AccBorderSE <- append(AccBorderSE, model_share[3,2])
```

```{r}
fit <- glm(ShareDV ~ ConditionIV, data=x_long[x_long$item_type==1,])

clusters <- cbind(x_long[x_long$item_type==1,]$ResponseId, x_long[x_long$item_type==1,]$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlyb <- append(AccOnlyb, model_share[2])
AccOnlySE <- append(AccOnlySE, model_share[2,2])

AccBorderb <- append(AccBorderb, model_share[3])
AccBorderSE <- append(AccBorderSE, model_share[3,2])
```

```{r}
fit <- glm(ShareDV ~ item_type*ConditionIV, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlyb <- append(AccOnlyb, model_share[7])
AccOnlySE <- append(AccOnlySE, model_share[7,2])

AccBorderb <- append(AccBorderb, model_share[10])
AccBorderSE <- append(AccBorderSE, model_share[10,2])
```

```{r}
fit <- glm(ShareDV ~ ConditionIV, data=x_long[x_long$item_type==2,])

clusters <- cbind(x_long[x_long$item_type==2,]$ResponseId, x_long[x_long$item_type==2,]$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlyb <- append(AccOnlyb, model_share[2])
AccOnlySE <- append(AccOnlySE, model_share[2,2])

AccBorderb <- append(AccBorderb, model_share[3])
AccBorderSE <- append(AccBorderSE, model_share[3,2])
```

```{r}
fit <- glm(ShareDV ~ ConditionIV, data=x_long[x_long$item_type==3,])

clusters <- cbind(x_long[x_long$item_type==3,]$ResponseId, x_long[x_long$item_type==3,]$itemU)

(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlyb <- append(AccOnlyb, model_share[2])
AccOnlySE <- append(AccOnlySE, model_share[2,2])

AccBorderb <- append(AccBorderb, model_share[3])
AccBorderSE <- append(AccBorderSE, model_share[3,2])
```

LIKING
```{r}
AccOnlybL <- c()
AccOnlySEL <- c()

AccBorderbL <- c()
AccBorderSEL <- c()
```

```{r}
fit <- glm(LikeDV ~ ConditionIV, data=x_long[x_long$item_type==0,])

clusters <- cbind(x_long[x_long$item_type==0,]$ResponseId, x_long[x_long$item_type==0,]$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlybL <- append(AccOnlybL, model_like[2])
AccOnlySEL <- append(AccOnlySEL, model_like[2,2])

AccBorderbL <- append(AccBorderbL, model_like[3])
AccBorderSEL <- append(AccBorderSEL, model_like[3,2])
```

```{r}
fit <- glm(LikeDV ~ ConditionIV, data=x_long[x_long$item_type==1,])

clusters <- cbind(x_long[x_long$item_type==1,]$ResponseId, x_long[x_long$item_type==1,]$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlybL <- append(AccOnlybL, model_like[2])
AccOnlySEL <- append(AccOnlySEL, model_like[2,2])

AccBorderbL <- append(AccBorderbL, model_like[3])
AccBorderSEL <- append(AccBorderSEL, model_like[3,2])
```

```{r}
fit <- glm(LikeDV ~ item_type*ConditionIV, data=x_long)

clusters <- cbind(x_long$ResponseId, x_long$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlybL <- append(AccOnlybL, model_like[7])
AccOnlySEL <- append(AccOnlySEL, model_like[7,2])

AccBorderbL <- append(AccBorderbL, model_like[10])
AccBorderSEL <- append(AccBorderSEL, model_like[10,2])
```

```{r}
fit <- glm(LikeDV ~ ConditionIV, data=x_long[x_long$item_type==2,])

clusters <- cbind(x_long[x_long$item_type==2,]$ResponseId, x_long[x_long$item_type==2,]$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlybL <- append(AccOnlybL, model_like[2])
AccOnlySEL <- append(AccOnlySEL, model_like[2,2])

AccBorderbL <- append(AccBorderbL, model_like[3])
AccBorderSEL <- append(AccBorderSEL, model_like[3,2])
```

```{r}
fit <- glm(LikeDV ~ ConditionIV, data=x_long[x_long$item_type==3,])

clusters <- cbind(x_long[x_long$item_type==3,]$ResponseId, x_long[x_long$item_type==3,]$itemU)

(model_like <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))

AccOnlybL <- append(AccOnlybL, model_like[2])
AccOnlySEL <- append(AccOnlySEL, model_like[2,2])

AccBorderbL <- append(AccBorderbL, model_like[3])
AccBorderSEL <- append(AccBorderSEL, model_like[3,2])
```

Make Dataframes.
```{r}
labels <- c("False", "True", "True vs False Discernment", "Non-political Social", "Political Social")

share_df <- data.frame(labels, AccOnlyb, AccBorderb)
share_df_long <- gather(share_df, conditionB, beta, AccOnlyb:AccBorderb)

share_df2 <- data.frame(labels, AccOnlySE, AccBorderSE)
share_df_long2 <- gather(share_df2, conditionSE, SE, AccOnlySE:AccBorderSE)

share_df_long <- cbind(share_df_long, share_df_long2)
share_df_long <- share_df_long[,-4]
```

```{r}
like_df <- data.frame(labels, AccOnlybL, AccBorderbL)
like_df_long <- gather(like_df, conditionB, beta, AccOnlybL:AccBorderbL)

like_df2 <- data.frame(labels, AccOnlySEL, AccBorderSEL)
like_df_long2 <- gather(like_df2, conditionSE, SE, AccOnlySEL:AccBorderSEL)

like_df_long <- cbind(like_df_long, like_df_long2)
like_df_long <- like_df_long[,-4]
```

```{r}
share_df_long$CI <- share_df_long$SE*qnorm(.05/2, lower.tail=F)
like_df_long$CI <- like_df_long$SE*qnorm(.05/2, lower.tail=F)

share_df_long$condition <- ifelse(grepl("AccOnly", share_df_long$conditionB), "Accuracy Only", "Accuracy + Borders")

like_df_long$condition <- ifelse(grepl("AccOnly", like_df_long$conditionB), "Accuracy Only", "Accuracy + Borders")

share_df_long$condition <- factor(share_df_long$condition, levels=c("Accuracy Only", "Accuracy + Borders"))
like_df_long$condition <- factor(like_df_long$condition, levels=c("Accuracy Only", "Accuracy + Borders"))

share_df_long$labels <- factor(share_df_long$labels, levels=c("Political Social", "Non-political Social", "True vs False Discernment", "True", "False"))
like_df_long$labels <- factor(like_df_long$labels, levels=c("Political Social", "Non-political Social", "True vs False Discernment", "True", "False"))
```

```{r}
ggplot(share_df_long, aes(x=beta, y=labels, col=labels))+facet_wrap(~condition)+
  geom_point()+
  geom_errorbar(aes(xmin=beta-CI, xmax=beta+CI), width=.2)+
  scale_color_manual(values=c("#660A60", "#C850B0", "black", "#2F7604", "#FFCB32"))+
  theme_classic()+ylab("")+
  xlab("")+geom_vline(xintercept=0, linetype="dotted", size=0.5)+
  theme(legend.position="none")
```

```{r}
ggplot(like_df_long, aes(x=beta, y=labels, col=labels))+facet_wrap(~condition)+
  geom_point()+
  geom_errorbar(aes(xmin=beta-CI, xmax=beta+CI), width=.2)+
  scale_color_manual(values=c("#660A60", "#C850B0", "black", "#2F7604", "#FFCB32"))+
  theme_classic()+ylab("")+
  xlab("")+geom_vline(xintercept=0, linetype="dotted", size=0.5)+
  theme(legend.position="none")
```



```{r}
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                      conf.interval=.95, .drop=TRUE) {
    library(plyr)

    # New version of length which can handle NA's: if na.rm==T, don't count them
    length2 <- function (x, na.rm=FALSE) {
        if (na.rm) sum(!is.na(x))
        else       length(x)
    }

    # This does the summary. For each group's data frame, return a vector with
    # N, mean, and sd
    datac <- ddply(data, groupvars, .drop=.drop,
      .fun = function(xx, col) {
        c(N    = length2(xx[[col]], na.rm=na.rm),
          mean = mean   (xx[[col]], na.rm=na.rm),
          sd   = sd     (xx[[col]], na.rm=na.rm)
        )
      },
      measurevar
    )

    # Rename the "mean" column    
    datac <- rename(datac, c("mean" = measurevar))

    datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean

    # Confidence interval multiplier for standard error
    # Calculate t-statistic for confidence interval: 
    # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
    ciMult <- qt(conf.interval/2 + .5, datac$N-1)
    datac$ci <- datac$se * ciMult

    return(datac)
}
```

Standard Error Corrections.
```{r}
share_CRSE <- c()

x_long_ControlFalse <- x_long %>% filter(ConditionIV==0 & item_type==0)
fit <- glm(ShareDV ~ 1, data=x_long_ControlFalse)
clusters <- cbind(x_long_ControlFalse$ResponseId, x_long_ControlFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_ControlTrue <- x_long %>% filter(ConditionIV==0 & item_type==1)
fit <- glm(ShareDV ~ 1, data=x_long_ControlTrue)
clusters <- cbind(x_long_ControlTrue$ResponseId, x_long_ControlTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_ControlPureSoc <- x_long %>% filter(ConditionIV==0 & item_type==2)
fit <- glm(ShareDV ~ 1, data=x_long_ControlPureSoc)
clusters <- cbind(x_long_ControlPureSoc$ResponseId, x_long_ControlPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_ControlPolSoc <- x_long %>% filter(ConditionIV==0 & item_type==3)
fit <- glm(ShareDV ~ 1, data=x_long_ControlPolSoc)
clusters <- cbind(x_long_ControlPolSoc$ResponseId, x_long_ControlPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_AccFalse <- x_long %>% filter(ConditionIV==1 & item_type==0)
fit <- glm(ShareDV ~ 1, data=x_long_AccFalse)
clusters <- cbind(x_long_AccFalse$ResponseId, x_long_AccFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_AccTrue <- x_long %>% filter(ConditionIV==1 & item_type==1)
fit <- glm(ShareDV ~ 1, data=x_long_AccTrue)
clusters <- cbind(x_long_AccTrue$ResponseId, x_long_AccTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_AccPureSoc <- x_long %>% filter(ConditionIV==1 & item_type==2)
fit <- glm(ShareDV ~ 1, data=x_long_AccPureSoc)
clusters <- cbind(x_long_AccPureSoc$ResponseId, x_long_AccPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_AccPolSoc <- x_long %>% filter(ConditionIV==1 & item_type==3)
fit <- glm(ShareDV ~ 1, data=x_long_AccPolSoc)
clusters <- cbind(x_long_AccPolSoc$ResponseId, x_long_AccPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_BorderFalse <- x_long %>% filter(ConditionIV==2 & item_type==0)
fit <- glm(ShareDV ~ 1, data=x_long_BorderFalse)
clusters <- cbind(x_long_BorderFalse$ResponseId, x_long_BorderFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_BorderTrue <- x_long %>% filter(ConditionIV==2 & item_type==1)
fit <- glm(ShareDV ~ 1, data=x_long_BorderTrue)
clusters <- cbind(x_long_BorderTrue$ResponseId, x_long_BorderTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_BorderPureSoc <- x_long %>% filter(ConditionIV==2 & item_type==2)
fit <- glm(ShareDV ~ 1, data=x_long_BorderPureSoc)
clusters <- cbind(x_long_BorderPureSoc$ResponseId, x_long_BorderPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])

x_long_BorderPolSoc <- x_long %>% filter(ConditionIV==2 & item_type==3)
fit <- glm(ShareDV ~ 1, data=x_long_BorderPolSoc)
clusters <- cbind(x_long_BorderPolSoc$ResponseId, x_long_BorderPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share_CRSE <- c(share_CRSE, model_share[2])
```

```{r}
like_CRSE <- c()

x_long_ControlFalse <- x_long %>% filter(ConditionIV==0 & item_type==0)
fit <- glm(LikeDV ~ 1, data=x_long_ControlFalse)
clusters <- cbind(x_long_ControlFalse$ResponseId, x_long_ControlFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_ControlTrue <- x_long %>% filter(ConditionIV==0 & item_type==1)
fit <- glm(LikeDV ~ 1, data=x_long_ControlTrue)
clusters <- cbind(x_long_ControlTrue$ResponseId, x_long_ControlTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_ControlPureSoc <- x_long %>% filter(ConditionIV==0 & item_type==2)
fit <- glm(LikeDV ~ 1, data=x_long_ControlPureSoc)
clusters <- cbind(x_long_ControlPureSoc$ResponseId, x_long_ControlPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_ControlPolSoc <- x_long %>% filter(ConditionIV==0 & item_type==3)
fit <- glm(LikeDV ~ 1, data=x_long_ControlPolSoc)
clusters <- cbind(x_long_ControlPolSoc$ResponseId, x_long_ControlPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_AccFalse <- x_long %>% filter(ConditionIV==1 & item_type==0)
fit <- glm(LikeDV ~ 1, data=x_long_AccFalse)
clusters <- cbind(x_long_AccFalse$ResponseId, x_long_AccFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_AccTrue <- x_long %>% filter(ConditionIV==1 & item_type==1)
fit <- glm(LikeDV ~ 1, data=x_long_AccTrue)
clusters <- cbind(x_long_AccTrue$ResponseId, x_long_AccTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_AccPureSoc <- x_long %>% filter(ConditionIV==1 & item_type==2)
fit <- glm(LikeDV ~ 1, data=x_long_AccPureSoc)
clusters <- cbind(x_long_AccPureSoc$ResponseId, x_long_AccPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_AccPolSoc <- x_long %>% filter(ConditionIV==1 & item_type==3)
fit <- glm(LikeDV ~ 1, data=x_long_AccPolSoc)
clusters <- cbind(x_long_AccPolSoc$ResponseId, x_long_AccPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_BorderFalse <- x_long %>% filter(ConditionIV==2 & item_type==0)
fit <- glm(LikeDV ~ 1, data=x_long_BorderFalse)
clusters <- cbind(x_long_BorderFalse$ResponseId, x_long_BorderFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_BorderTrue <- x_long %>% filter(ConditionIV==2 & item_type==1)
fit <- glm(LikeDV ~ 1, data=x_long_BorderTrue)
clusters <- cbind(x_long_BorderTrue$ResponseId, x_long_BorderTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_BorderPureSoc <- x_long %>% filter(ConditionIV==2 & item_type==2)
fit <- glm(LikeDV ~ 1, data=x_long_BorderPureSoc)
clusters <- cbind(x_long_BorderPureSoc$ResponseId, x_long_BorderPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])

x_long_BorderPolSoc <- x_long %>% filter(ConditionIV==2 & item_type==3)
fit <- glm(LikeDV ~ 1, data=x_long_BorderPolSoc)
clusters <- cbind(x_long_BorderPolSoc$ResponseId, x_long_BorderPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like_CRSE <- c(like_CRSE, model_share[2])
```

```{r}
x_long2 <- x_long %>% filter(!is.na(ShareDV))
x_plot <- summarySE(x_long2, measurevar = "ShareDV", groupvars = c("ConditionIV", "item_type"))
x_plot$CRSE <- share_CRSE
x_plot$CI <- x_plot$CRSE*qnorm(.05/2, lower.tail=F)

x_plot$Condition <- NA
x_plot$Condition[x_plot$ConditionIV==0] <- "Control"
x_plot$Condition[x_plot$ConditionIV==1] <- "Accuracy Prompt Only"
x_plot$Condition[x_plot$ConditionIV==2] <- "Accuracy Prompt + Borders"

x_plot$Condition <- factor(x_plot$Condition, levels=c("Control", "Accuracy Prompt Only", "Accuracy Prompt + Borders"))

x_plot$itemType[x_plot$item_type==0] <- "False"
x_plot$itemType[x_plot$item_type==1] <- "True"
x_plot$itemType[x_plot$item_type==2] <- "Non-political Social"
x_plot$itemType[x_plot$item_type==3] <- "Political Social"

x_plot$itemType <- factor(x_plot$itemType, levels=c("False", "True", "Non-political Social", "Political Social"))

x_plot
```

```{r}
ggplot(x_plot, aes(x=Condition, y=ShareDV, fill=itemType)) + 
    geom_bar(position=position_dodge(), stat="identity") +
    geom_errorbar(aes(ymin=ShareDV-CI, ymax=ShareDV+CI),
                  width=.15,                    
                  position=position_dodge(.9))+scale_fill_manual(name="Post Type", values=c("#FFCB32", "#2F7604", "#C850B0", "#660A60")) + labs(y="Sharing Probability", x="Condition")+theme_classic()
```

```{r}
x_long3 <- x_long %>% filter(!is.na(LikeDV))
x_plot <- summarySE(x_long3, measurevar = "LikeDV", groupvars = c("ConditionIV", "item_type"))
x_plot$CRSE <- like_CRSE
x_plot$CI <- x_plot$CRSE*qnorm(.05/2, lower.tail=F)

x_plot$Condition <- NA
x_plot$Condition[x_plot$ConditionIV==0] <- "Control"
x_plot$Condition[x_plot$ConditionIV==1] <- "Accuracy Prompt Only"
x_plot$Condition[x_plot$ConditionIV==2] <- "Accuracy Prompt + Borders"

x_plot$Condition <- factor(x_plot$Condition, levels=c("Control", "Accuracy Prompt Only", "Accuracy Prompt + Borders"))

x_plot$itemType[x_plot$item_type==0] <- "False"
x_plot$itemType[x_plot$item_type==1] <- "True"
x_plot$itemType[x_plot$item_type==2] <- "Non-political Social"
x_plot$itemType[x_plot$item_type==3] <- "Political Social"

x_plot$itemType <- factor(x_plot$itemType, levels=c("False", "True", "Non-political Social", "Political Social"))

x_plot
```

```{r}
ggplot(x_plot, aes(x=Condition, y=LikeDV, fill=itemType)) + 
    geom_bar(position=position_dodge(), stat="identity") +
    geom_errorbar(aes(ymin=LikeDV-CI, ymax=LikeDV+CI),
                  width=.15,                    
                  position=position_dodge(.9))+scale_fill_manual(name="Post Type", values=c("#FFCB32", "#2F7604", "#C850B0", "#660A60")) + labs(y="Liking Probability", x="Condition")+theme_classic()
```

Collapse Treats.

Standard Error Corrections.
```{r}
share2_CRSE <- share_CRSE[1:4]

x_long_TreatFalse <- x_long %>% filter(Treat==1 & item_type==0)
fit <- glm(ShareDV ~ 1, data=x_long_TreatFalse)
clusters <- cbind(x_long_TreatFalse$ResponseId, x_long_TreatFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share2_CRSE <- c(share2_CRSE, model_share[2])

x_long_TreatTrue <- x_long %>% filter(Treat==1 & item_type==1)
fit <- glm(ShareDV ~ 1, data=x_long_TreatTrue)
clusters <- cbind(x_long_TreatTrue$ResponseId, x_long_TreatTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share2_CRSE <- c(share2_CRSE, model_share[2])

x_long_TreatPureSoc <- x_long %>% filter(Treat==1 & item_type==2)
fit <- glm(ShareDV ~ 1, data=x_long_TreatPureSoc)
clusters <- cbind(x_long_TreatPureSoc$ResponseId, x_long_TreatPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share2_CRSE <- c(share2_CRSE, model_share[2])

x_long_TreatPolSoc <- x_long %>% filter(Treat==1 & item_type==3)
fit <- glm(ShareDV ~ 1, data=x_long_TreatPolSoc)
clusters <- cbind(x_long_TreatPolSoc$ResponseId, x_long_TreatPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
share2_CRSE <- c(share2_CRSE, model_share[2])
```

```{r}
like2_CRSE <- like_CRSE[1:4]

x_long_TreatFalse <- x_long %>% filter(Treat==1 & item_type==0)
fit <- glm(LikeDV ~ 1, data=x_long_TreatFalse)
clusters <- cbind(x_long_TreatFalse$ResponseId, x_long_TreatFalse$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like2_CRSE <- c(like2_CRSE, model_share[2])

x_long_TreatTrue <- x_long %>% filter(Treat==1 & item_type==1)
fit <- glm(LikeDV ~ 1, data=x_long_TreatTrue)
clusters <- cbind(x_long_TreatTrue$ResponseId, x_long_TreatTrue$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like2_CRSE <- c(like2_CRSE, model_share[2])

x_long_TreatPureSoc <- x_long %>% filter(Treat==1 & item_type==2)
fit <- glm(LikeDV ~ 1, data=x_long_TreatPureSoc)
clusters <- cbind(x_long_TreatPureSoc$ResponseId, x_long_TreatPureSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like2_CRSE <- c(like2_CRSE, model_share[2])

x_long_TreatPolSoc <- x_long %>% filter(Treat==1 & item_type==3)
fit <- glm(LikeDV ~ 1, data=x_long_TreatPolSoc)
clusters <- cbind(x_long_TreatPolSoc$ResponseId, x_long_TreatPolSoc$itemU)
(model_share <- coeftest(fit, vcov.=vcovCL(fit, cluster=clusters, type="HC0")))
like2_CRSE <- c(like2_CRSE, model_share[2])
```


```{r}
x_long2 <- x_long %>% filter(!is.na(ShareDV))
x_plot <- summarySE(x_long2, measurevar = "ShareDV", groupvars = c("Treat", "item_type"))
x_plot$CRSE <- share2_CRSE
x_plot$CI <- x_plot$CRSE*qnorm(.05/2, lower.tail=F)

x_plot$Condition <- NA
x_plot$Condition[x_plot$Treat==0] <- "Control"
x_plot$Condition[x_plot$Treat==1] <- "Treatment"

x_plot$Condition <- factor(x_plot$Condition, levels=c("Control", "Treatment"))

x_plot$itemType[x_plot$item_type==0] <- "False"
x_plot$itemType[x_plot$item_type==1] <- "True"
x_plot$itemType[x_plot$item_type==2] <- "Non-political Social"
x_plot$itemType[x_plot$item_type==3] <- "Political Social"

x_plot$itemType <- factor(x_plot$itemType, levels=c("False", "True", "Non-political Social", "Political Social"))

x_plot
```

```{r}
ggplot(x_plot, aes(x=Condition, y=ShareDV, fill=itemType)) + 
    geom_bar(position=position_dodge(), stat="identity") +
    geom_errorbar(aes(ymin=ShareDV-CI, ymax=ShareDV+CI),
                  width=.15,                    
                  position=position_dodge(.9))+scale_fill_manual(name="Post Type", values=c("#FFCB32", "#2F7604", "#C850B0", "#660A60")) + labs(y="Sharing Probability", x="Condition")+theme_classic()
```

```{r}
x_long3 <- x_long %>% filter(!is.na(LikeDV))
x_plot <- summarySE(x_long3, measurevar = "LikeDV", groupvars = c("Treat", "item_type"))
x_plot$CRSE <- like2_CRSE
x_plot$CI <- x_plot$CRSE*qnorm(.05/2, lower.tail=F)

x_plot$Condition <- NA
x_plot$Condition[x_plot$Treat==0] <- "Control"
x_plot$Condition[x_plot$Treat==1] <- "Treatment"

x_plot$Condition <- factor(x_plot$Condition, levels=c("Control", "Treatment"))

x_plot$itemType[x_plot$item_type==0] <- "False"
x_plot$itemType[x_plot$item_type==1] <- "True"
x_plot$itemType[x_plot$item_type==2] <- "Non-political Social"
x_plot$itemType[x_plot$item_type==3] <- "Political Social"

x_plot$itemType <- factor(x_plot$itemType, levels=c("False", "True", "Non-political Social", "Political Social"))

x_plot
```

```{r}
ggplot(x_plot, aes(x=Condition, y=LikeDV, fill=itemType)) + 
    geom_bar(position=position_dodge(), stat="identity") +
    geom_errorbar(aes(ymin=LikeDV-CI, ymax=LikeDV+CI),
                  width=.15,                    
                  position=position_dodge(.9))+scale_fill_manual(name="Post Type", values=c("#FFCB32", "#2F7604", "#C850B0", "#660A60")) + labs(y="Liking Probability", x="Condition")+theme_classic()
```


